home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-06-14 | 19.6 KB | 531 lines | [TEXT/PJMM] |
- unit Options;
-
- {File name: Options.p}
- {Function: Handle a Window}
- {History: 6/10/89 Original by Prototyper. }
-
- interface
- uses
- globals, FixMath, TEConvert;
-
- procedure preparewidth (i: integer);
-
- procedure prepareheight (i: integer);
-
- procedure SetFields;
-
- procedure SetDefaultPREC;
-
- {Initialize us so all our routines can be activated}
- procedure Init_Options;
-
- {Record the status of all edit fields and buttons and update the list}
- procedure Recordstatus;
-
- {Close our window}
- procedure Close_Options (whichWindow: WindowPtr; var theInput: TEHandle);
-
- {Open our window and draw everything}
- procedure Open_Options (var theInput: TEHandle);
-
- {Update our window, someone uncovered a part of us}
- procedure Update_Options (whichWindow: WindowPtr);
-
- {Handle action to our window, like controls}
- procedure Do_Options (myEvent: EventRecord; var theInput: TEHandle);
-
- implementation
-
- const
- TitleFieldid = 23; {Edit text ID}
- WidthFieldid = 24; {Edit text ID}
- HeightFieldid = 25; {Edit text ID}
- var
- tempRect, temp2Rect: Rect; {Temporary rectangle}
- Index: Integer; {For looping}
- CtrlHandle: ControlHandle; {Control handle}
- sTemp, sTemp1: Str255; {Get text entered, temp holding}
- List_I_Titles: ListHandle; {List Manager list handle}
- Rect_I_Titles: Rect; {List Manager list rectangle}
- dataBounds: Rect; {For use by lists}
- cSize: Point; {For use by lists}
- theRow: integer; {Used for adding rows to lists}
- num: extended;
- fixednum: Fixed;
- theCell: Cell;
-
- {=================================}
-
- procedure SetTeWidth (i: integer);
- begin
- num := PREC4.size[i].h / 120;
- fixednum := X2Fix(num);
- NumToString(HiWord(Fixednum), sTemp);
- num := (num - Hiword(Fixednum)) * 100;
- fixednum := X2Fix(num);
- NumToString(HiWord(Fixednum), sTemp1);
- sTemp := concat(sTemp, '.', sTemp1);
- TESetText(Pointer(Ord4(@sTemp) + 1), length(sTemp), WidthFieldhndl);{Place default text in the TE area}
- SetRect(TempRect, 220, 82, 270, 102);{left,top,right,bottom of WidthField Rectangle}
- TEUpdate(TempRect, WidthFieldhndl);
- end;
-
- {=================================}
-
- procedure SetTeHeight (i: integer);
- begin
- num := PREC4.size[i].v / 120;
- fixednum := X2Fix(num);
- NumToString(HiWord(Fixednum), sTemp);
- num := (num - Hiword(Fixednum)) * 100;
- fixednum := X2Fix(num);
- NumToString(HiWord(Fixednum), sTemp1);
- sTemp := concat(sTemp, '.', sTemp1);
- TESetText(Pointer(Ord4(@sTemp) + 1), length(sTemp), HeightFieldhndl);{Place default text in the TE area}
- SetRect(TempRect, 326, 82, 376, 102);{left,top,right,bottom of HeightField Rectangle}
- TEUpdate(TempRect, HeightFieldhndl);
- end;
-
- {=================================}
- procedure SetFields;
- var
- i, datalen: integer;
- begin
- for i := 6 downto 1 do
- begin
- dataLen := length(PREC4.Title[i]);
- cSize.v := i - 1;
- LSetCell(Pointer(ord(@PREC4.Title[i]) + 1), dataLen, cSize, List_I_Titles); {Set string in row }
- LSetSelect(false, cSize, List_I_Titles);
- end;
- SetTeWidth(1);
- SetTeHeight(1);
- TESetText(Pointer(Ord4(@PREC4.Title[1]) + 1), length(PREC4.Title[1]), TitleFieldhndl);{Place default text in the TE area}
- SetRect(TempRect, 220, 40, 380, 62); {left,top,right,bottom of TitleField Rectangle}
- TEUpdate(TempRect, TitleFieldhndl);
- LSetSelect(true, cSize, List_I_Titles);
- end;
- {=================================}
-
- procedure SetDefaultPREC;
- begin
- with prec4 do
- begin
- numberofbuttons := 5;
- Size[1].v := 1320; { 11.0" }
- Size[1].h := 1020; { 8.50" }
- Size[2].v := 1400; { 11.66" }
- Size[2].h := 990; { 8.25" }
- Size[3].v := 1680; { 14.0" }
- Size[3].h := 1020; { 8.50" }
- Size[4].v := 1440; { 14.0" }
- Size[4].h := 990; { 8.50" }
- Size[5].v := 1320; { 14.0" }
- Size[5].h := 1680; { 8.50" }
- Size[6].v := 0; { undefined }
- Size[6].h := 0; { undefined }
- Title[1] := 'US Letter';
- Title[2] := 'A4 Letter';
- Title[3] := 'US Legal';
- Title[4] := 'International Fanfold';
- Title[5] := 'Computer Paper';
- Title[6] := '?';
- end;
- setFields;
- SetWTitle(MyWindow, 'Page Option Defaults');
- end;
-
- {=================================}
-
- {Initialize us so all our routines can be activated}
- procedure Init_Options;
-
- begin {Start of Window initialize routine}
- MyWindow := nil; {Make sure other routines know we are not valid yet}
- end; {End of procedure}
-
- {=================================}
-
- {Record the status of all edit fields and buttons and update the list}
- procedure Recordstatus;
- var
- i, datalen: integer;
- tempnumber: real;
- function strtox (s: str255): extended;
- var
- number: longint;
- total, multiplier: real;
- decimalposition, i: integer;
- begin
- total := 0;
- decimalposition := pos('.', s);
- multiplier := 1;
- for i := (decimalposition - 1) downto 1 do
- begin
- stringtonum(s[i], number);
- total := total + (number * multiplier);
- multiplier := multiplier * 10;
- end;
- multiplier := 0.1;
- for i := (decimalposition + 1) to length(s) do
- begin
- stringtonum(s[i], number);
- total := total + (number * multiplier);
- multiplier := multiplier / 10;
- end;
- if decimalposition = 0 then
- begin
- multiplier := 1;
- total := 0;
- for i := length(s) downto 1 do
- begin
- stringtonum(s[i], number);
- total := total + (number * multiplier);
- multiplier := multiplier * 10;
- end;
- end;
- strtox := total;
- end;
- begin
- Csize.h := 0;
- TERecToStr(TitleFieldhndl, sTemp);
- PREC4.Title[cSize.v + 1] := sTemp;
- dataLen := length(sTemp);
- LSetCell(Pointer(ord(@sTemp) + 1), dataLen, cSize, List_I_Titles); {Set string in row }
- TERecToStr(WidthFieldhndl, sTemp);
- i := 120;
- tempnumber := strtox(sTemp) * i;
- PREC4.size[cSize.v + 1].h := trunc(tempnumber);
-
- TERecToStr(HeightFieldhndl, sTemp1);
- tempnumber := strtox(sTemp1) * i;
- PREC4.size[cSize.v + 1].v := trunc(tempnumber);
-
- end;
-
- {=================================}
-
- {Close our window}
- procedure Close_Options;
-
- begin {Start of Window close routine}
- if (MyWindow <> nil) and ((MyWindow = whichWindow) or (ord4(whichWindow) = -1)) then{See if we should close this window}
- begin
- if (theInput = TitleFieldhndl) then{See if this Text Edit field handle}
- theInput := nil; {Clear the handle used}
- if (theInput = WidthFieldhndl) then{See if this Text Edit field handle}
- theInput := nil; {Clear the handle used}
- if (theInput = HeightFieldhndl) then{See if this Text Edit field handle}
- theInput := nil; {Clear the handle used}
- DisposeWindow(MyWindow);{Clear window and controls}
- MyWindow := nil; {Make sure other routines know we are open}
- end; {End for if (MyWindow<>nil)}
- end; {End of procedure}
-
- {=================================}
-
- {Update our window, someone uncovered a part of us}
- procedure UpDate_Options;
- var
- SavePort: WindowPtr; {Place to save the last port}
- sTemp: Str255; {Temporary string}
-
- begin {Start of Window update routine}
- Recordstatus;
- if (MyWindow <> nil) and (MyWindow = whichWindow) then{Handle an open when already opened}
- begin
- GetPort(SavePort); {Save the current port}
- SetPort(MyWindow); {Set the port to my window}
- TextFont(systemFont); {Set the font to draw in}
- {Draw a string of text, }
- SetRect(tempRect, 273, 85, 318, 102);
- sTemp := '" X';
- TextBox(Pointer(ord(@sTemp) + 1), length(sTemp), tempRect, teJustLeft);
- TextFont(applFont); {Set the default application font}
-
- TextFont(systemFont); {Set the font to draw in}
- {Draw a string of text, }
- SetRect(tempRect, 378, 85, 423, 102);
- sTemp := '"';
- TextBox(Pointer(ord(@sTemp) + 1), length(sTemp), tempRect, teJustLeft);
- TextFont(applFont); {Set the default application font}
-
- {Update a TE box, US Letter }
- SetRect(TempRect, 220, 40, 380, 65);{left,top,right,bottom}
- FrameRect(TempRect); {Frame this TE area}
- InsetRect(TempRect, 3, 3);{Surround the TE area}
- if (TitleFieldhndl <> nil) then{Only update if TE area is valid}
- begin {Update the TE area}
- TEUpdate(TempRect, TitleFieldhndl);{Update the TE area}
- TextFont(applFont);{Set the default application font}
- end; {End of the TE area}
-
- {Update a TE box, Width }
- SetRect(TempRect, 220, 82, 270, 102);{left,top,right,bottom}
- FrameRect(TempRect); {Frame this TE area}
- InsetRect(TempRect, 3, 3);{Surround the TE area}
- if (WidthFieldhndl <> nil) then{Only update if TE area is valid}
- begin {Update the TE area}
- TEUpdate(TempRect, WidthFieldhndl);{Update the TE area}
- TextFont(applFont);{Set the default application font}
- end; {End of the TE area}
-
- {Update a TE box, Height }
- SetRect(TempRect, 326, 82, 376, 102);{left,top,right,bottom}
- FrameRect(TempRect); {Frame this TE area}
- InsetRect(TempRect, 3, 3);{Surround the TE area}
- if (HeightFieldhndl <> nil) then{Only update if TE area is valid}
- begin {Update the TE area}
- TEUpdate(TempRect, HeightFieldhndl);{Update the TE area}
- TextFont(systemFont);{Set the default application font}
- end; {End of the TE area}
-
- {Update a List, Titles }
- SetRect(TempRect, 21, 21, 204, 117);{left,top,right,bottom}
- TempRect.Right := TempRect.Right - 15;{Go inside the scroll bar}
- InsetRect(TempRect, -1, -1);{Surround the List area}
- FrameRect(TempRect); {Frame this List area}
- if (List_I_Titles <> nil) then{Only update if List area is valid}
- LUpdate(MyWindow^.visRgn, List_I_Titles);{Update the List area}
-
- DrawControls(MyWindow);{Draw all the controls}
- SetPort(SavePort); {Restore the old port}
- end; {End for if (MyWindow<>nil)}
- end; {End of procedure}
-
- {=================================}
-
- {Open our window and draw everything}
- procedure Open_Options;
- var
- Index: Integer; {For looping}
- dataBounds: Rect; {For making lists}
- cSize: Point; {For making lists}
-
-
-
- {This is a routine used to add strings to an existing list}
- procedure Add_List_String (theString: Str255; theList: ListHandle);
- var
- theRow: integer; {The Row that we are adding}
-
- begin
- if (theList <> nil) then
- begin
- cSize.h := 0; {Point to the correct column}
- theRow := LAddRow(1, 200, theList);{Add another row at the end of the list}
- cSize.v := theRow; {Point to the row just added}
- sTemp := theString; {Get the string to add}
- LSetCell(Pointer(ord(@sTemp) + 1), length(sTemp), cSize, theList);{Place string in row just created}
- LDraw(cSize, theList); {Draw the new string}
- end;
- end;
-
-
- begin {Start of Window open routine}
-
- if (MyWindow = nil) then {Handle an open when already opened}
- begin
- MyWindow := GetNewWindow(1, nil, Pointer(-1));{Get the window from the resource file}
- SetPort(MyWindow); {Prepare to write into our window}
-
- {Open a TE box, Width }
- SetRect(TempRect, 220, 82, 270, 102);{left,top,right,bottom}
- FrameRect(TempRect); {Frame this TE area}
- InsetRect(TempRect, 3, 3);{Restore the original size}
- WidthFieldhndl := TENew(TempRect, TempRect);{Create the TE area}
- if (theInput <> nil) then{See if there is already a TE area}
- TEDeactivate(theInput);{Yes, so turn it off}
- theInput := WidthFieldhndl; {Activate the TE area}
- HLock(Handle(WidthFieldhndl));{Lock the handle before using it}
- WidthFieldhndl^^.txFont := systemFont;{Font to use for the TE area}
- WidthFieldhndl^^.fontAscent := 12;{Font ascent}
- WidthFieldhndl^^.lineHeight := 12 + 3 + 1;{Font ascent + descent + leading}
- HUnLock(Handle(WidthFieldhndl));{UnLock the handle when done}
- sTemp := '8.50';
- TESetText(Pointer(Ord4(@sTemp) + 1), length(sTemp), WidthFieldhndl);{Place default text in the TE area}
- TEActivate(WidthFieldhndl); {Make the TE area active}
- TEUpdate(TempRect, WidthFieldhndl);
- TextFont(applFont); {Set the default application font}
-
- {Open a TE box, Height }
- SetRect(TempRect, 326, 82, 376, 102);{left,top,right,bottom}
- FrameRect(TempRect); {Frame this TE area}
- InsetRect(TempRect, 3, 3);{Restore the original size}
- HeightFieldhndl := TENew(TempRect, TempRect);{Create the TE area}
- if (theInput <> nil) then{See if there is already a TE area}
- TEDeactivate(theInput);{Yes, so turn it off}
- theInput := HeightFieldhndl; {Activate the TE area}
- HLock(Handle(HeightFieldhndl));{Lock the handle before using it}
- HeightFieldhndl^^.txFont := systemFont;{Font to use for the TE area}
- HeightFieldhndl^^.fontAscent := 12;{Font ascent}
- HeightFieldhndl^^.lineHeight := 12 + 3 + 1;{Font ascent + descent + leading}
- HUnLock(Handle(HeightFieldhndl));{UnLock the handle when done}
- sTemp := '11.0';
- TESetText(Pointer(Ord4(@sTemp) + 1), length(sTemp), HeightFieldhndl);{Place default text in the TE area}
- TEActivate(HeightFieldhndl); {Make the TE area active}
- TEUpdate(TempRect, HeightFieldhndl);
- TextFont(applFont); {Set the default application font}
-
- {Open a TE box, Title }
- SetRect(TempRect, 220, 40, 380, 62);{left,top,right,bottom}
- FrameRect(TempRect); {Frame this TE area}
- InsetRect(TempRect, 3, 3);{Restore the original size}
- TitleFieldhndl := TENew(TempRect, TempRect);{Create the TE area}
- if (theInput <> nil) then{See if there is already a TE area}
- TEDeactivate(theInput);{Yes, so turn it off}
- theInput := TitleFieldhndl; {Activate the TE area}
- HLock(Handle(TitleFieldhndl));{Lock the handle before using it}
- TitleFieldhndl^^.txFont := systemFont;{Font to use for the TE area}
- TitleFieldhndl^^.fontAscent := 12;{Font ascent}
- TitleFieldhndl^^.lineHeight := 12 + 3 + 1;{Font ascent + descent + leading}
- HUnLock(Handle(TitleFieldhndl));{UnLock the handle when done}
- sTemp := 'US Letter';
- TESetText(Pointer(Ord4(@sTemp) + 1), length(sTemp), TitleFieldhndl);{Place default text in the TE area}
- TEActivate(TitleFieldhndl); {Make the TE area active}
- TEUpdate(TempRect, TitleFieldhndl);
- TextFont(applFont); {Set the default application font}
-
- {Make a List, Titles }
- SetRect(TempRect, 21, 21, 204, 117);{left,top,right,bottom}
- Rect_I_Titles := tempRect;{Save the list position}
- TempRect.Right := TempRect.Right - 15;{Go inside the scroll bar area}
- InsetRect(TempRect, -1, -1);{Surround the List area}
- FrameRect(TempRect); {Frame this List area}
- InsetRect(TempRect, 1, 1);{Restore to the List area}
- SetRect(dataBounds, 0, 0, 1, 0);{Make the empty list}
- cSize.h := TempRect.Right - TempRect.Left;{Get the width of the list}
- cSize.v := 16; {Set the HEIGHT of each list element}
- List_I_Titles := LNew(TempRect, dataBounds, cSize, 0, MyWindow, TRUE, FALSE, FALSE, TRUE);{Create the list}
- List_I_Titles^^.selFlags := lOnlyOne + lNoNilHilite;{Set for only one active item at a time}
- LdoDraw(TRUE, List_I_Titles);{Draw this list structure}
- cSize.h := 0; {Point to the correct column, starts at zero}
- Add_List_String('US Letter', List_I_Titles);{Add in the new string}
- Add_List_String('A4 Letter', List_I_Titles);{Add in the new string}
- Add_List_String('US Legal', List_I_Titles);{Add in the new string}
- Add_List_String('International Fanfold', List_I_Titles);{Add in the new string}
- Add_List_String('Computer Paper', List_I_Titles);{Add in the new string}
- Add_List_String('?', List_I_Titles);{Add in the new string}
- cSize.h := 0; {All elements are in column 0}
- cSize.v := 0; {Select the first list element}
- LSetSelect(TRUE, cSize, List_I_Titles);
-
- ShowWindow(MyWindow); {Show the window now}
- SelectWindow(MyWindow);{Bring our window to the front}
- SetDefaultPrec;
- end {End for if (MyWindow<>nil)}
- else
- SelectWindow(MyWindow);{Already open, so show it}
-
- end; {End of procedure}
-
- {=================================}
-
- {Handle action to our window, like controls}
- procedure Do_Options;
-
- var
- RefCon: longint; {RefCon for controls}
- code: integer; {Location of event in window or controls}
- theValue: integer; {Current value of a control}
- whichWindow: WindowPtr; {Window pointer where event happened}
- myPt: Point; {Point where event happened}
- theControl: ControlHandle; {Handle for a control}
- MyErr: OSErr; {OS error returned}
- DoubleClick: boolean; {Used by lists}
- datalen: integer;
-
- begin {Start of Window handler}
- Recordstatus;
- if (MyWindow <> nil) then {Handle only when the window is valid}
- begin
- code := FindWindow(myEvent.where, whichWindow);{Get where in window and which window}
-
- if (myEvent.what = MouseDown) and (MyWindow = whichWindow) then{}
- begin {}
- myPt := myEvent.where;{Get mouse position}
- with MyWindow^.portBits.bounds do{Make it relative}
- begin
- myPt.h := myPt.h + left;
- myPt.v := myPt.v + top;
- end;
-
-
- SetRect(tempRect, 220, 40, 380, 62);{Position of the TE}
- if PtInRect(myPt, tempRect) then{Check for pressed in the TE US Letter }
- begin
- if (theInput <> nil) then{See if there is already a TE area}
- TEDeactivate(theInput);{Yes, so turn it off}
- theInput := TitleFieldhndl;
- TEActivate(theInput);{Turn it on}
- TEClick(myPt, FALSE, TitleFieldhndl);
- end;
-
-
- SetRect(tempRect, 220, 82, 270, 102);{Position of the TE}
- if PtInRect(myPt, tempRect) then{Check for pressed in the TE Width }
- begin
- if (theInput <> nil) then{See if there is already a TE area}
- TEDeactivate(theInput);{Yes, so turn it off}
- theInput := WidthFieldhndl;
- TEActivate(theInput);{Turn it on}
- TEClick(myPt, FALSE, WidthFieldhndl);
- end;
-
-
- SetRect(tempRect, 326, 82, 376, 102);{Position of the TE}
- if PtInRect(myPt, tempRect) then{Check for pressed in the TE Height }
- begin
- if (theInput <> nil) then{See if there is already a TE area}
- TEDeactivate(theInput);{Yes, so turn it off}
- theInput := HeightFieldhndl;
- TEActivate(theInput);{Turn it on}
- TEClick(myPt, FALSE, HeightFieldhndl);
- end;
-
- if PtInRect(myPt, Rect_I_Titles) then
- begin
- DoubleClick := LClick(myPt, myEvent.modifiers, List_I_Titles);
- if DoubleClick then
- begin
- end;
- begin
- cSize := LLastClick(List_I_Titles);
- datalen := 100;
- LGetCell(Pointer(ord(@sTemp) + 1), dataLen, cSize, List_I_Titles);{Get string in row }
- if not (LGetSelect(false, cSize, List_I_Titles)) then
- begin
- theCell.v := 0;
- theCell.h := 0;
- if LGetSelect(true, theCell, List_I_Titles) then
- begin
- cSize := theCell;
- datalen := 100;
- LGetCell(Pointer(ord(@sTemp) + 1), dataLen, cSize, List_I_Titles); {Get string in row }
- end;
- end;
- TESetText(Pointer(Ord4(@PREC4.Title[cSize.v + 1]) + 1), dataLen, TitleFieldhndl); {Place text in the TE area}
- SetRect(TempRect, 220, 40, 380, 62); {left,top,right,bottom of TitleField Rectangle}
- TEUpdate(TempRect, TitleFieldhndl);
- SetTeWidth(cSize.v + 1);
- SetTeHeight(cSize.v + 1);
- end;
- end;
-
- end;
-
- if (MyWindow = whichWindow) and (code = inContent) then{for our window}
- begin
-
- code := FindControl(myPt, whichWindow, theControl);{Get type of control}
-
- if (code <> 0) then{Check type of control}
- code := TrackControl(theControl, myPt, nil);{Track the control}
-
- end; {End for if (MyWindow=whichWindow)}
- end; {End for if (MyWindow<>nil)}
- end; {End of procedure}
-
- {=================================}
-
- end. {End of unit}